package com.excellence.controller;

import com.excellence.datamodel.Result;
import com.excellence.pojo.Answer;
import com.excellence.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 沈秉璋
 * @ClassName AnswerController
 * @Description TODO
 * @date 2024/4/8 11:39
 * @Version 1.0
 */
//@Controller
//@ResponseBody
@RestController
@RequestMapping("/api/answer")
public class AnswerController {
    @Autowired
    private AnswerService answerService;

    /**
     * @description: 假装删除把deleteId改为1
     * @author: ShenBingZhang
     * @date: 2024/4/9 19:59
     * @param: [id]
     * @return: [java.lang.Long]
     **/
    @PutMapping("/deleteByKey")
    Result deleteByKey(Long id) {
        int res = answerService.deleteByKey(id);
        return Result.success(res);
    }

    /**
     * @description: 真删除
     * @author: ShenBingZhang
     * @date: 2024/4/9 20:00
     * @param: [id]
     * @return: [java.lang.Long]
     **/
    @DeleteMapping("/deleteByPrimaryKey")
    Result deleteByPrimaryKey(Long id) {
        int res = answerService.deleteByPrimaryKey(id);
        return Result.success(res);
    }

    @PostMapping("/insert")
    Result insert(Answer record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = answerService.insert(record, files);
        return Result.success(res);
    }

    @PostMapping("/insertSelective")
    Result insertSelective(Answer record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = answerService.insertSelective(record, files);
        return Result.success(res);
    }

    @GetMapping("/selectByPrimaryKey")
    Result selectByPrimaryKey(Long id) {
        Answer res = answerService.selectByPrimaryKey(id);
        return Result.success(res);
    }

    @GetMapping("/selectAll")
    Result selectAll() {
        List<Answer> res = answerService.selectAll();
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKeySelective")
    Result updateByPrimaryKeySelective(Answer record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = answerService.updateByPrimaryKeySelective(record, files);
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKey")
    Result updateByPrimaryKey(Answer record, @RequestParam(value = "files", required = false) List<MultipartFile> files) {
        int res = answerService.updateByPrimaryKey(record, files);
        return Result.success(res);
    }
}
